<template>
  <div id="app">
    <el-container>
      <!-- 头部导航 -->
      <el-header class="app-header">
        <div class="header-content">
          <div class="logo">
            <el-icon><DatabaseOutlined /></el-icon>
            <span class="title">分布式KV服务</span>
          </div>
          <div class="nav-links">
            <el-menu
              :default-active="$route.path"
              mode="horizontal"
              router
              class="nav-menu"
            >
              <el-menu-item index="/dashboard">
                <el-icon><Monitor /></el-icon>
                <span>仪表板</span>
              </el-menu-item>
              <el-menu-item index="/kv-manager">
                <el-icon><Key /></el-icon>
                <span>KV管理</span>
              </el-menu-item>
              <el-menu-item index="/batch-operations">
                <el-icon><Operation /></el-icon>
                <span>批量操作</span>
              </el-menu-item>
              <el-menu-item index="/statistics">
                <el-icon><TrendCharts /></el-icon>
                <span>统计分析</span>
              </el-menu-item>
            </el-menu>
          </div>
        </div>
      </el-header>

      <!-- 主内容区域 -->
      <el-main class="app-main">
        <router-view />
      </el-main>

      <!-- 底部信息 -->
      <el-footer class="app-footer">
        <div class="footer-content">
          <span>分布式KV服务 v1.0.0 | 基于Cassandra + Redis + Guava混合架构</span>
          <div class="system-info">
            <el-tag size="small" type="success" v-if="systemStatus.online">在线</el-tag>
            <el-tag size="small" type="danger" v-else>离线</el-tag>
            <span class="separator">|</span>
            <span>延迟: {{ systemStatus.latency }}ms</span>
          </div>
        </div>
      </el-footer>
    </el-container>
  </div>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from 'vue'
import { useSystemStore } from './store/pinia_stores.js'

const systemStore = useSystemStore()
const systemStatus = ref({
  online: true,
  latency: 0
})

let healthCheckInterval = null

// 系统健康检查
const checkSystemHealth = async () => {
  try {
    const startTime = Date.now()
    await systemStore.checkHealth()
    const latency = Date.now() - startTime
    
    systemStatus.value = {
      online: true,
      latency
    }
  } catch (error) {
    systemStatus.value = {
      online: false,
      latency: 0
    }
  }
}

onMounted(() => {
  // 初始健康检查
  checkSystemHealth()
  
  // 定期健康检查(每30秒)
  healthCheckInterval = setInterval(checkSystemHealth, 30000)
})

onUnmounted(() => {
  if (healthCheckInterval) {
    clearInterval(healthCheckInterval)
  }
})
</script>

<style scoped>
.app-header {
  background: linear-gradient(90deg, #409eff 0%, #67c23a 100%);
  color: white;
  padding: 0;
  height: 60px;
  line-height: 60px;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100%;
  padding: 0 20px;
}

.logo {
  display: flex;
  align-items: center;
  font-size: 20px;
  font-weight: bold;
}

.logo .el-icon {
  margin-right: 8px;
  font-size: 24px;
}

.nav-menu {
  border: none;
  background: transparent;
}

.nav-menu .el-menu-item {
  color: white;
  border-bottom: 2px solid transparent;
}

.nav-menu .el-menu-item:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.nav-menu .el-menu-item.is-active {
  background: rgba(255, 255, 255, 0.2);
  border-bottom-color: white;
  color: white;
}

.app-main {
  padding: 20px;
  min-height: calc(100vh - 120px);
  background: #f5f7fa;
}

.app-footer {
  background: #303133;
  color: #909399;
  height: 60px;
  line-height: 60px;
  padding: 0;
}

.footer-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100%;
  padding: 0 20px;
  font-size: 14px;
}

.system-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.separator {
  color: #606266;
}
</style>